package com.hand.qt24953.order.app.service;

import com.hand.qt24953.order.constant.OrderStatus;
import com.hand.qt24953.order.domain.entity.SoHeader;
import com.hand.qt24953.order.domain.repository.SoHeaderRepository;
import org.hzero.boot.scheduler.infra.annotation.JobHandler;
import org.hzero.boot.scheduler.infra.enums.ReturnT;
import org.hzero.boot.scheduler.infra.handler.IJobHandler;
import org.hzero.boot.scheduler.infra.tool.SchedulerTool;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * @author qiutao 2019/8/6 15:19
 */
@JobHandler("CloseOrder")
public class CloseOrderJobService implements IJobHandler {
    private final SoHeaderRepository soHeaderRepository;
    @Autowired
    public CloseOrderJobService(SoHeaderRepository soHeaderRepository) {
        this.soHeaderRepository = soHeaderRepository;
    }

    @Override
    public ReturnT execute(Map<String, String> map, SchedulerTool tool) {
        List<SoHeader> list = soHeaderRepository.select(SoHeader.FIELD_ORDER_STATUS, OrderStatus.APPROVED.toString());
        for (SoHeader soHeader : list) {
            soHeader.setOrderStatus(OrderStatus.CLOSED.toString());
        }
        soHeaderRepository.batchUpdateByPrimaryKey(list);
        return ReturnT.SUCCESS;
    }
}
